convert string to byte java

47

convert string to byte java -

  String example = "Convert Java String";
  byte[] bytes = example.getBytes();

String to Byte array Java -

import java.util.Arrays;

public class StringToByte {
 public static void main(String[] args) {
  String str = "Example String";
  byte[] b = str.getBytes();
  System.out.println("Array " + b);
  System.out.println("Array as String" + Arrays.toString(b));
 }
}

Comments

Submit
0 Comments